//
//  MovieViewController.m
//  stotyboard豆瓣电影
//
//  Created by Zhao YanBin on 16/1/4.
//  Copyright © 2016年 panxue. All rights reserved.
//

#import "MovieViewController.h"
#import "NetworkHandler.h"
#import "UIImageView+WebCache.h"
#import "MovieTableViewCell.h"
#import "Movie2ViewController.h"
#import "movie2model.h"
@interface MovieViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataArr;
@end

@implementation MovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self data];
}
-(void)data
{
    NSString *str = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php";
    [NetworkHandler GETWithURL:str completion:^(id result) {
//        self.dataArr = result[@"result"];
        self.dataArr = [NSMutableArray array];
//        movie2model *m = [[movie2model alloc] init];
        
        self.dataArr = [movie2model modelHanderWithArray:result[@"result"]];
//        [_tableView reloadData];
        [self.tableView reloadData];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  _dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MovieTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    movie2model *m = _dataArr[indexPath.row];
    cell.movieName.text = m.movieName;
//    NSDictionary *dic = _dataArr[indexPath.row];
//    cell.movieName.text = dic[@"movieName"];
//    [cell.pic_url sd_setImageWithURL:[NSURL URLWithString:dic[@"pic_url"]] ];
    [cell.pic_url sd_setImageWithURL:[NSURL URLWithString:m.pic_url]];
    return  cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 170;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
//    _index = [_tableView indexPathForCell:sender];
    Movie2ViewController *acVC = segue.destinationViewController;
    
    movie2model *m = _dataArr[_tableView.indexPathForSelectedRow.row];
    acVC.movieid =m.movieId;
}

@end
